package com.gold.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.gold.common.HttpUtils;
import com.gold.wechat.utils.WechatPayPath;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 支付相关
 * @author XiaoHao
 * @date 2022-06-01 11:12
 */
@Controller
@RequestMapping("wechat/Pay")
public class WechatPayController {
    @Value("${wechat.url}")
    private  String URLPATH;

    /**
     * 开启抢红包
     * @return
     */
    @RequestMapping(value = "StartOpenRedEnvelopes", method = RequestMethod.POST)
    @ResponseBody
    public String StartOpenRedEnvelopes(@RequestBody JSONObject parm){
        String  url = URLPATH + WechatPayPath.StartOpenRedEnvelopes;
        JSONObject jsonObject = HttpUtils.doPost(url,parm.toJSONString());
        return jsonObject.toJSONString();
    }

    /**
     * POST /api/Pay/StopOpenRedEnvelopes/{wxId}
     * 关闭抢红包
     * @return
     */
    @RequestMapping(value = "StopOpenRedEnvelopes", method = RequestMethod.POST)
    @ResponseBody
    public String StopOpenRedEnvelopes(@RequestBody JSONObject parm){
        Object wxId = parm.get("wxId");
        String  url = URLPATH + WechatPayPath.StopOpenRedEnvelopes+wxId;
        JSONObject jsonObject = HttpUtils.doPost(url,parm.toJSONString());
        return jsonObject.toJSONString();
    }
}
